home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_009 / proff / pxlex.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  190 lines

  1.  
  2.  
  3. #include <stdio.h>
  4. #include <math.h>
  5. #include <ctype.h>
  6.  
  7. /* translation table for control chars */
  8.  
  9. char c_ctrl[] = { 
  10.         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  11.         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  12.         0,  0,  0,  0,  0,  0,  0,  0,
  13.         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  14.         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  15.         0,  0,  0,  0,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
  16.         10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
  17.         23, 25, 26, 27, 28, 29, 30, 31, 0,  1,  2,  3,  4,  5,
  18.         6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  19.         20, 21, 22, 23, 24, 25, 26, 0,  0,  0,  0,  0
  20.         };
  21.  
  22. /*
  23.  * getval - evaluate optional numeric argument
  24.  *
  25.  * increments i
  26.  */
  27. int
  28. getval(buf,i,argtyp)
  29. char buf[];
  30. int *i;
  31. int *argtyp;
  32. {
  33.     int j,k;
  34.  
  35.     j = *i;
  36.     k = *argtyp;
  37.  
  38.     skipbl(buf, &j);
  39.     k = buf[j];
  40.     if (k == '+' || k == '-')
  41.         j++;
  42.     *i = j;
  43.     *argtyp = k;
  44.     return(ctoi(buf,i));
  45. }
  46.  
  47. /*
  48.  * getarg - get the next argument from the buffer
  49.  *
  50.  * return values:      -1 - no argument
  51.  *            n - number of chars in argument
  52.  *
  53.  * also handles quoted ("..") strings. If a quote is wanted
  54.  * in the string, use "" or \". quotes are stripped.
  55.  *
  56.  * argument delimiters: blank, tab or comma (,).
  57.  *
  58.  * increments i
  59.  *
  60.  */
  61. int
  62. getarg(buf,i,arg)
  63. char buf[];
  64. int *i;
  65. char arg[];
  66. {
  67.     int j,k;
  68.     register char ch;
  69.  
  70.     j = *i;
  71.  
  72.     k = -1;
  73.     skipbl(buf,&j);
  74.     if (buf[j] != '\0') {
  75.         k = 0;
  76.         if (buf[j] == '\"') {
  77.             j++;
  78.             while (buf[j] != '\0') {
  79.                 if (buf[j] == '\"') {
  80.                     if (buf[j+1] == '\"') {
  81.                         arg[k++] = '\"';
  82.                         j += 2;
  83.                     }
  84.                     else
  85.                         break;
  86.                 }
  87.                 arg[k++] = buf[j++];
  88.             }
  89.             arg[k] = '\0';
  90.             j++;            /* skip the quote */
  91.             /* peek next char */
  92.             if (isalnum(buf[j]))
  93.                 error("improper argument list.");
  94.             j++;            /* skip the delimeter */
  95.         }
  96.         else {
  97.             ch = buf[j];
  98.             while (ch != ' '&& 
  99.                 ch != '\t'     && 
  100.                 ch != ','     &&
  101.                 ch != '\r'     && 
  102.                 ch != '\n'     && 
  103.                 ch != '\0') {
  104.                 arg[k++] = buf[j++];
  105.                 ch = buf[j];
  106.             }
  107.             arg[k] = '\0';
  108.             if (ch != '\0')    /* if non-null delimiter, skip */
  109.                 j++;
  110.         }
  111.         *i = j;
  112.     }
  113.     return(k);
  114. }
  115.  
  116. /*
  117.  * getpstr - get a special string to print out
  118.  *
  119.  */
  120. getpstr(buf,out)
  121. register char *buf;
  122. register char *out;
  123. {
  124.     register int i;
  125.     register char c, cc;
  126.     register char *num;
  127.     char numbuf[9];
  128.  
  129.     while(*buf != '\n' && *buf != '\0') {
  130.         c = *buf;
  131.         switch(c) {
  132.         case ' ':
  133.         case '\t':
  134.             while (*buf == ' ' || *buf == '\t')
  135.                 buf++;    /* skip blanks */
  136.             break;
  137.         case '\\':
  138.             if (*(buf+1) != '\0') {
  139.                 *out++ = *(buf+1);
  140.                 buf += 2;
  141.             }
  142.             else
  143.                 buf++;
  144.             break;
  145.         case '^':
  146.             if ((cc = c_ctrl[*(buf+1)]) != 0)
  147.                 *out++ = cc;
  148.             buf += 2;
  149.             break;
  150.         case '\"':
  151.             buf++;    /* skip the quote */
  152.             while (*buf != '\0') {
  153.                 if (*buf != '\"')
  154.                     *out++ = *buf++;
  155.                 else if (*(buf+1) == '\"') {
  156.                         *out++ = '\"';
  157.                         buf += 2;
  158.                 }
  159.                 else
  160.                     break;
  161.             }
  162.             buf++;    /* skip the quote */
  163.             break;
  164.         case '0':
  165.         case '1':
  166.         case '2':
  167.         case '3':
  168.         case '4':
  169.         case '5':
  170.         case '6':
  171.         case '7':
  172.         case '8':
  173.         case '9':
  174.             num = numbuf;
  175.             while (isdigit(*buf))
  176.                 *num++ = *buf++;
  177.             *num = '\0';
  178.             if ((i = atoi(numbuf)) > 256)
  179.                 error("non-ascii char value in write string.");
  180.             else if (i > 0)        /* do not output null */
  181.                 *out++ = (char) i;
  182.             break;
  183.         default:
  184.             *out++ = *buf++;
  185.         }
  186.     }
  187.     *out = '\0';
  188. }
  189.  
  190.